package org.zcl.controller;

import lombok.extern.slf4j.Slf4j;
import org.zcl.entity.model.ApiResponse;

@Slf4j
public class BaseAction {

    protected static final String SUCCESS = "0";
    protected static final String FAIL = "-1";

    public <T> ApiResponse<T> returnSuccess(T data) {
        ApiResponse<T> apiResponse = new ApiResponse<>();
        apiResponse.setCode(SUCCESS);
        apiResponse.setMsg("success");
        apiResponse.setData(data);
        return apiResponse;
    }

    public <T> ApiResponse<T> returnError(T data, String message) {
        ApiResponse<T> apiResponse = new ApiResponse<>();
        apiResponse.setCode(FAIL);
        apiResponse.setErrMsg(message);
        apiResponse.setData(data);
        apiResponse.setMsg("fail");
        return apiResponse;
    }
}
